package binarysearch;

/**
 * Created with IntelliJ IDEA.
 * Description: 二分查找改动版
 * User: YJ
 * Date: 2023-9-23
 * Time: 21:31
 */
public class TestBinarySearchAlternative {
    public static int binarySearchAlternative(int[] arr,int target) {
        int i = 0;                  //第一处
        int j = arr.length;         //第二处
        while (i < j) {
            //中间值
            int mid = (i + j) >>> 1;
            if(target < arr[mid]) {
                j = mid;            //第三处
            } else if (arr[mid] < target) {
                i = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
